let maxNo = null;
let lock = true;
$NG.AllReady(function (
	page,
	{
		useValuesChange,
		useClick,
		useUpdateRow,
		useUpdateRows,
		useDataIndexChange,
		useBeforeClick,
		useAction,
	}
) {
	console.log("Data ready event triggered");
	var mstform = $NG.getCmpApi("p_form_equipment_list");
	var dgrid = $NG.getCmpApi("p_form_equipment_list_d");
	//   useBeforeClick(async function ({ args }) {
	//     dgrid.getRows().forEach((item) => {
	//       if (item.u_pur_qty) {
	//         item.u_rest_qty = item.u_pur_qty; // 将u_pur_qty的值赋给u_rest_qty
	//       } else {
	//         item.u_rest_qty = 0; // 将u_pur_qty的值赋给u_rest_qty
	//       }
	//       // 查看是否存在清单
	//       let exit = true
	//       console.log(`保存设置1`,lock);
	//       if(!lock){
	//         $NG.confirm('确认提交？').then(function (result) {
	//             exit = result
	//         });
	//       }
	//       console.log(`保存设置2`,exit);
	//       return exit
	//     });
	//   }, "save");
	// 增加跳转链接
	var dgrid1 = $NG.getCmpApi("p_form_equipment_list_impl");
	var dgrid2 = $NG.getCmpApi("p_form_equipment_list_svc");
	var dgrid3 = $NG.getCmpApi("p_form_equipment_list_rd");

	//按钮隐藏
	$NG.getCmpApi("toolbar_p_form_equipment_list_d").getItem("attachment").setHidden()

	useAction("clickHighlight")(function (e) {
		// //获取当前选中行
		// const url = window.location.href;
		// const arr = $NG.split(url, "/");
		// const urlp = arr[2];
		// const { u_bill_no } = $NG
		// 	.getCmpApi("p_form_equipment_list_impl")
		// 	.getSelectedRow();
		// let flag = $NG.confirm("您确定要跳转到合同信息吗？");
		// if (flag) {
		// 	$NG.execServer(
		// 		"getssfyPhid",
		// 		{
		// 			bill_no: `'${u_bill_no}'`,
		// 		},
		// 		function (res) {
		// 			const datas = JSON.parse(res.data)[0].extendObjects;
		// 			if (datas.phid) {
		// 				// 弹出确认框
		// 				$NG.open(
		// 					"http://" +
		// 						urlp +
		// 						`/react/index.html#/customform/detail?id=${datas.phid}&otype=view&busType=EFORM9000000034&isSso=1` +
		// 						{ AppTitle: "实施费用预算单-查看" }
		// 				);
		// 			}
		// 		}

		// 		//帮助字段赋值
		// 	);
		// }
	});
    const tableArr = ["p_form_equipment_list_impl","p_form_equipment_list_svc","p_form_equipment_list_rd"]
    tableArr.forEach(item=>{
        $NG.updateUI(updater => {
            updater.editGrid[item].u_source_phid.setProps((p)=>{
                return {
                    ...p, editor: {
                      ...p.editor,
                      onDoubleClick(args){
                        const urlp = window.location.href.split("#")[0]
                        let url = ""
                        console.log('双击成功!!!!!', args);
                        switch(item){
                            case "p_form_equipment_list_impl":
                                url = urlp+`#/customform/detail?id=${dgrid1.getSelectedData()[0].u_source_phid}&otype=view&busType=EFORM9000000034&isSso=1&AppTitle=${encodeURI("实施费用预算单-查看")}`
                                break;
                            case "p_form_equipment_list_svc":
                                url = urlp+`#/customform/detail?id=${dgrid2.getSelectedData()[0].u_source_phid}&otype=view&busType=EFORM9000000035&isSso=1&AppTitle=${encodeURI("服务费用预算单-查看")}`
                                break;
                            case "p_form_equipment_list_rd":
                                url = urlp+`#/customform/detail?id=${dgrid3.getSelectedData()[0].u_source_phid}&otype=view&busType=EFORM9000000129&isSso=1&AppTitle=${encodeURI("研发费用预算单-查看")}`
                                break;
                        }
                        // 弹出确认框
                        console.log(url);
						$NG.open(url)
                      }
                    }
                }
            })
        })
        // $NG.updateUI((updater) => {
        //     console.log('测试',item,updater,updater.editGrid,updater.editGrid[item]);
        //     updater.editGrid[item].u_source_phid.setProps({
        //         // 双击事件
        //         onDoubleClick() {
        //             console.log(arg);
        //             console.log("双击确认");
        //                 // $NG.open(
        //                 //     "http://nginx.clouddev.hisense.com" +
        //                 //         "/PMS/PCM/CntM/CntMEdit?otype=view&id=" +
        //                 //         u_cnt_phid,
        //                 //     { AppTitle: "合同信息" }
        //                 // );
        //         },
        //     });
        // });
    })
    
	useBeforeClick(async ({ args }) => {
		console.log(`保存`);
		console.log(lock);
		let is = true
		let isArr=[]
		await dgrid.getRows().forEach((item,index) => {
			if (item.u_pur_qty) {
				item.u_rest_qty = item.u_pur_qty; // 将u_pur_qty的值赋给u_rest_qty
				console.log(item.u_pur_qty, item.u_rest_qty);
			} else {
				item.u_rest_qty = 0; // 将u_pur_qty的值赋给u_rest_qty
			}
			if(item.u_pur_name){
				if(!item.u_pur_item_category){
					is = false
					isArr.push(index+1)
				}
			}
		});
		// 查看是否存在清单
		let exit = true;
		console.log(`保存设置1`, lock);
		if(!is){
			$NG.alert(`设备清单明细第 ${isArr.join("、")} 行 拟采购类型为空`)
			console.log(`错误！！！！！`);
			return false
		}
		if (!lock) {
			exit = await $NG.confirm("确认提交？");
			console.log(exit, "保存测试");
		}
		console.log(`保存设置2`, exit);
		


		return exit;

	}, "save");

	useValuesChange(({ args }) => {
		console.log(`实施是否清算监听`, args);
		const _lock = args[0].u_is_implementation_settle.value;
		console.log(`1`);
		$NG.updateUI(function (updater, state) {
			console.log(`实施清算副监听`, updater);
			if (Number(_lock) === 1) {
				console.log(`1`);
				updater.fieldSetForm.p_form_equipment_list.u_implementation_settle_time.setProps(
					{
						required: true, //required是否必输
						disabled: false,
					}
				);
			} else {
				console.log(`0`);
				updater.fieldSetForm.p_form_equipment_list.u_implementation_settle_time.setProps(
					{
						required: false, //required是否必输
						disabled: true,
					}
				);
			}
		});
	}, "p_form_equipment_list.u_is_implementation_settle");

	useValuesChange(({ args }) => {
		console.log(`实施是否清算监听`, args);
		const _lock = args[0].u_is_service_settle.value;
		console.log(`1`);
		$NG.updateUI(function (updater, state) {
			console.log(`实施清算副监听`, updater);
			if (Number(_lock) === 1) {
				console.log(`1`);
				updater.fieldSetForm.p_form_equipment_list.u_service_settle_time.setProps(
					{
						required: true, //required是否必输
						disabled: false,
					}
				);
			} else {
				console.log(`0`);
				updater.fieldSetForm.p_form_equipment_list.u_service_settle_time.setProps(
					{
						required: false, //required是否必输
						disabled: true,
					}
				);
			}
		});
	}, "p_form_equipment_list.u_is_service_settle");

	{
		//按钮事件BEGIN
		useClick(async function ({ args }) {
			insertClick();
		}, "user_insert");
	} //按钮事件ENG

	{
		//初始化逻辑BEGIN
		cntMFilter();
		cntDFilter();
		if ($NG.getCmpApi("p_form_equipment_list").getItem("phid_pc").getValue()) {
			getPtInfoByPhid();
		}

		//页面条件
		if (page.oType == "add" || page.oType == "edit" || page.oType == "copy") {
			$NG.updateState(function (updater, state) {
				if (!mstform.getItem("u_create_org").getValue()) {
					updater.data.p_form_equipment_list.setProps({
						u_create_org: $NG.getUser().orgID,
						u_create_org_EXName: $NG.getUser().orgName,
						u_using_org: $NG.getUser().userID,
						u_using_org_EXName: $NG.getUser().orgName,
					});
				}
			});
		}
	} //初始化逻辑END

	{
		getCntCount(
			"p_form_equipment_list",
			"u_cnt",
			getCntMInfoByPhid,
			danjvchaxun
		);
		//表头字段变化逻辑BEGIN
		useValuesChange(({ args }) => {
			cntMFilter();
			getPtInfoByPhid();

			getCntCount(
				"p_form_equipment_list",
				"u_cnt",
				getCntMInfoByPhid,
				danjvchaxun
			);
		}, "p_form_equipment_list.phid_pc");
		useValuesChange(({ args }) => {
			cntDFilter();
			getCntMInfoByPhid();
		}, "p_form_equipment_list.u_cnt");
		useValuesChange(({ args }) => {
			caculatedgrid();
		}, "p_form_equipment_list.u_win_bid_svc_amt");
	} //表头字段变化逻辑END
	if (mstform) {
		// 隐藏
		const _arrHideM = [
			"u_total_cost_amt_vat",
			"u_total_cost_change",
			"u_pur_cost_vat",
			"u_sub_cost",
			"u_self_cost_vat",
			// "u_pur_reduction_cost",
		];
		_arrHideM.forEach((field) => {
			$NG.updateUI((updater) => {
				updater.fieldSetForm.p_form_equipment_list[field].setProps({
					hidden: true, //隐藏
				});
			});
		});
	}
	/* dgrid */
	if (dgrid) {
		const _arrHideD = [
			"u_cnt_prc_vat",
			"u_cnt_amt_vat",
			"u_sub_no",
			"u_sub_prc_vat",
			"u_sub_cost_vat",
			"u_sub_invoice_type",
			"u_pur_no",
			"u_pur_prc_vat",
			"u_pur_cost_vat",
			"u_pur_invoice_type",
			"u_self_no",
			"u_self_prc_vat",
			"u_self_cost_vat",
			"u_self_invoice_type",
		];
		_arrHideD.forEach((item) => {
			if (item.includes("sub")) {
				$NG.updateUI((updater) => {
					updater.editGrid.p_form_equipment_list_d["Cell60"][item].setProps({
						hidden: true, //隐藏
					});
				});
			} else if (item.includes("pur")) {
				$NG.updateUI((updater) => {
					updater.editGrid.p_form_equipment_list_d["Cell61"][item].setProps({
						hidden: true, //隐藏
					});
				});
			} else if (item.includes("self")) {
				$NG.updateUI((updater) => {
					updater.editGrid.p_form_equipment_list_d["Cell62"][item].setProps({
						hidden: true, //隐藏
					});
				});
			}
		});
		useDataIndexChange(({ args, instance }) => {
			const record = args[0];
			if (record.u_cnt_item) {
				getCntDInfoByPhid(record);
			}
		}, "u_cnt_item");
		useUpdateRows(({ args, table }) => {
			console.log("updatedGridData");
			const rows = args[0];
			rows.forEach((items, index) => {
				// // 未税单价   = 含税单价/1+税率
				// args[0].u_sub_prc = (args[0].u_sub_prc_vat || 0) / (1 + (args[0].u_sub_tax_rate || 0));
				// 含税单价   = 未税单价*（1+税率）
				items.u_sub_prc_vat =
					(items.u_sub_prc || 0) * (1 + (items.u_sub_tax_rate || 0));
				// 含税成本 = 数量 * 含税单价
				items.u_sub_cost_vat =
					(items.u_sub_qty || 0) * (items.u_sub_prc_vat || 0);
				// 成本未税 = 数量 * 含税单价 / 1+税率
				items.u_sub_cost = (items.u_sub_qty || 0) * (items.u_sub_prc || 0);
				// items.u_sub_cost = ((items.u_qty || 0) * (items.u_sub_prc_vat || 0)) / (1 + (items.u_sub_tax_rate || 0));

				// 采购
				// items.u_pur_prc = (items.u_pur_prc_vat || 0) / (1 + items.u_pur_tax_rate || 0);
				items.u_pur_prc_vat =
					(items.u_pur_prc || 0) * (1 + items.u_pur_tax_rate || 0);
				items.u_pur_cost_vat =
					(items.u_pur_qty || 0) * (items.u_pur_prc_vat || 0);
				items.u_pur_cost = (items.u_pur_qty || 0) * (items.u_pur_prc || 0);
				// items.u_pur_cost = ((items.u_qty || 0) * (items.u_pur_prc_vat || 0)) / (1 + (items.u_pur_tax_rate || 0));

				// 自制
				// items.u_self_prc = (items.u_self_prc_vat || 0) * (1 + items.u_self_tax_rate || 0);
				items.u_self_prc_vat =
					(items.u_self_prc || 0) * (1 + items.u_self_tax_rate || 0);
				items.u_self_cost_vat =
					(items.u_self_qty || 0) * (items.u_self_prc_vat || 0);
				items.u_self_cost = (items.u_self_qty || 0) * (items.u_self_prc || 0);
				// items.u_self_cost = ((items.u_qty || 0) * (items.u_self_prc_vat || 0)) / (1 + (items.u_self_tax_rate || 0));
			});
		});
	}
	const toolbar_dgrid = $NG.getCmpApi("toolbar_p_form_equipment_list_d");
	if (toolbar_dgrid) {
		toolbar_dgrid.insert({
			id: "user_insert",
			text: "插行",
			iconCls: "icon-InsertRow",
		});
		toolbar_dgrid.insert({
			id: "template_download",
			text: "模板下载",
			iconCls: "icon-InsertRow",
		});
		//按钮点击事件
		useClick(async function ({ args }) {
			// console.log("按钮点击");
			var data = {
				LinkRep_tarSheets: "0",
				LinkRep_tarCells: "b1",
				LinkRep_srcParas: `${mstform.getItem("u_cnt").getValue()}`,
			};
			var replinkdata = encodeURIComponent(JSON.stringify(data));
			const url = window.location.href;
			const arr = $NG.split(url, "/");
			const url_domain = arr[2];
			const url_path = `/RW/DesignFrame/ReportView?rep_src=0&rep_code=202502100002&replink=true&datavaluetype=cell&replinkdata=${replinkdata}`;
			$NG.open(`http://${url_domain}${url_path}`, { AppTitle: "模板下载" });
		}, "template_download");
	}

	//

	useUpdateRows(({ args, table }) => {
		console.log("useUpdateRows begin");
		const rows = args[0];
		const clearList = {}; // 用于存储清单编号
		let clearCodeCounter = 1; // 清单编码计数器，从 1 开始
		let lock = false; //要刷新吗
		rows.forEach((items, index) => {
			//1、自动生成设备清单
			const { u_equipment_list_name, u_model } = items;
			const key = `${u_equipment_list_name}_${u_model}`; // 根据名称和型号生成唯一标识符

			if (!clearList[key]) {
				// 如果清单编号不存在，则生成新的编号
				const serialPart = String(clearCodeCounter).padStart(4, "0"); // 将计数器格式化为4位
				clearList[key] = "A" + serialPart; // 生成清单编号
				clearCodeCounter++;
			}

			//根据导入的合同编码匹配合同清单
			if (!items.u_cnt_item) {
				getCntDInfoByNo(items);
				lock = true;
			}
			console.log(`正则`, /^\d{14}$/.test(items.u_equipment_list_no));
			if (!/^\d{14}$/.test(items.u_equipment_list_no)) {
				items.u_equipment_list_no = autoCreateNo(index + 1);
			}
			//3、匹配拟分包项
			if (!items.u_sub_item && items.u_sub_no) {
				console.log("通过 u_sub_no 匹配拟分包项");
				$NG.execServer(
					"getItemdataByNo",
					{ itemno: "'" + items.u_sub_no + "'" },
					function (res) {
						if (res.count > 0) {
							var data = JSON.parse(res.data)[0].extendObjects; //单返回值
							items.u_sub_item = data.phid;
							items.u_sub_item_EXName = data.itemno;
							items.u_sub_name = data.itemname;
							items.u_sub_item_category = data.phid_resbs;
							items.u_sub_item_category_EXName = data.name;
							items.u_sub_item_msunit_EXName = data.msunit_name;
							items.u_sub_item_msunit = data.msunit_phid;
							items.u_sub_ggxh = data.spec;
							items.u_fwgczdj = data.prc_ad;
						} else {
							console.log(items.u_sub_no + ":useUpdateRows没有找到拟分包清单");
							// items.u_sub_item = null;
							// items.u_sub_item_EXName = null;
						}
					}
				);
				items.u_sub_invoice_type = "8570000000000151";
				items.u_sub_invoice_type_EXName = "6%增值税专用发票";
				dgrid.refreshView();
			}

			//3、匹配拟采购项目
			if (!items.u_pur_item && items.u_pur_no) {
				console.log("通过 u_pur_no 匹配拟采购项目");
				$NG.execServer(
					"getItemdataByNo",
					{ itemno: "'" + items.u_pur_no + "'" },
					function (res) {
						if (res.count > 0) {
							var purdata = JSON.parse(res.data)[0].extendObjects; //单返回值
							items.u_pur_item = purdata.phid;
							items.u_pur_item_EXName = purdata.itemno;
							items.u_pur_name = purdata.itemname;
							items.u_pur_item_category = purdata.phid_resbs;
							items.u_pur_item_category_EXName = purdata.name;
							items.u_pur_item_msunit = purdata.msunit_phid;
							items.u_pur_item_msunit_EXName = purdata.msunit_name;
							items.u_pur_ggxh = purdata.spec;
							items.u_cgzdj = purdata.prc_ad;
						} else {
							console.log("useUpdateRows没有找到拟采购清单");
							// items.u_u_pur_item = null;
							// items.u_u_pur_item_EXName = null;
						}
					}
				);
				$NG.execServer(
					"getIsDj",
					{
						phid_wl: items.u_pur_item,
						phid_pc: mstform.getItem("phid_pc").getValue(),
					},
					(res) => {
						console.log(
							`By物料获得单价信息`,
							res,
							mstform.getItem("phid_pc").getValue(),
							items.u_pur_item
						);
						if (res.count == 0) return;
						const _data = JSON.parse(res.data)[0].extendObjects;
						items.u_priced_prc = _data.u_target_prc;
						items.u_is_priced = 1;
						dgrid.refreshView();
					}
				);
				items.u_pur_invoice_type = "8570000000000154";
				items.u_pur_invoice_type_EXName = "13%增值税专用发票";
				dgrid.refreshView();
			}

			//4、匹配自制项目
			if (!items.u_self_item && items.u_self_no) {
				console.log("通过 u_self_no 匹配自制项目");
				$NG.execServer(
					"getItemdataByNo",
					{ itemno: "'" + items.u_self_no + "'" },
					function (res) {
						if (res.count > 0) {
							var data = JSON.parse(res.data)[0].extendObjects; //单返回值

							items.u_self_item = data.phid;
							items.u_self_item_EXName = data.itemno;
							items.u_self_name = data.itemname;
							items.u_self_item_category = data.phid_resbs;
							items.u_self_item_category_EXName = data.name;
							items.u_self_ggxh = data.spec;
							items.u_self_item_msunit = data.msunit_phid;
							items.u_self_item_msunit_EXName = data.msunit_name;
							items.u_zzzdj = data.prc_ad;
						} else {
							console.log("useUpdateRows没有找到拟自制清单");
							// items.u_self_item = null;
							// items.u_self_item_EXName = null;
						}
						dgrid.refreshView();
					}
				);
			}
		});
		if (lock) {
			dgrid.refreshView();
			console.log(`刷新了`);
		}
		console.log("useUpdateRows end");
	}, "p_form_equipment_list_d");

	useUpdateRow(({ args, table }) => {
		console.log("useUpdateRow begin");
		const items = args[0];
		console.log("测试", items);

		//2. 更新拟分包项
		if (items.u_sub_item) {
			$NG.execServer(
				"getItemdataByPhid",
				{ phid: items.u_sub_item },
				function (res) {
					if (res.count > 0) {
						var data = JSON.parse(res.data)[0].extendObjects; //单返回值

						items.u_sub_item_category = data.phid_resbs;
						items.u_sub_item_category_EXName = data.name;
						items.u_sub_name = data.itemname;
						items.u_sub_ggxh = data.spec;
						items.u_sub_item_msunit_EXName = data.msunit_name;
						items.u_sub_item_msunit = data.msunit_phid;
						items.u_sub_item_category = data.phid_resbs;
						items.u_sub_item_category_EXName = data.res_bs_name;
						items.u_fwgczdj = data.prc_ad;
					} else {
						// console.log('没有找到拟分包清单')
						// items.u_u_sub_item = null;
						// items.u_u_sub_item_EXName = null;
						// items.u_sub_ggxh = null;
					}
					dgrid.refreshView();
				}
			);
		}

		//3. 更新拟采购项
		console.log(`编码`, items.u_pur_item);
		if (items.u_pur_item) {
			$NG.execServer(
				"getItemdataByPhid",
				{ phid: items.u_pur_item },
				function (res) {
					console.log(`测试请求数据`, res);
					if (res.count > 0) {
						var purdata = JSON.parse(res.data)[0].extendObjects; //单返回值

						items.u_pur_item_category = purdata.phid_resbs;
						items.u_pur_item_category_EXName = purdata.name;
						items.u_pur_name = purdata.itemname;
						items.u_pur_ggxh = purdata.spec;
						items.u_pur_item_msunit_EXName = purdata.msunit_name;
						items.u_pur_item_msunit = purdata.msunit_phid;
						items.u_pur_item_category = purdata.phid_resbs;
						items.u_pur_item_category_EXName = purdata.res_bs_name;
						items.u_cgzdj = purdata.prc_ad;
					} else {
					}
					dgrid.refreshView();
				}
			);
			$NG.execServer(
				"getIsDj",
				{
					phid_wl: items.u_pur_item,
					phid_pc: mstform.getItem("phid_pc").getValue(),
				},
				(res) => {
					console.log(
						`By物料获得单价信息`,
						res,
						mstform.getItem("phid_pc").getValue(),
						items.u_pur_item
					);
					if (res.count == 0) return;
					const _data = JSON.parse(res.data)[0].extendObjects;
					items.u_priced_prc = _data.u_target_prc;
					items.u_is_priced = 1;
					dgrid.refreshView();
				}
			);
		}

		//4. 更新拟自制项
		if (items.u_self_item) {
			$NG.execServer(
				"getItemdataByPhid",
				{ phid: items.u_self_item },
				function (res) {
					if (res.count > 0) {
						var data = JSON.parse(res.data)[0].extendObjects; //单返回值

						items.u_self_item_category = data.phid_resbs;
						items.u_self_item_category_EXName = data.name;
						items.u_self_name = data.itemname;
						items.u_self_ggxh = data.spec;
						items.u_self_item_msunit = data.msunit_phid;
						items.u_self_item_msunit_EXName = data.msunit_name;
						items.u_self_item_category_EXName = data.res_bs_name;
						items.u_self_item_category = data.phid_resbs;
						items.u_zzzdj = data.prc_ad;
					} else {
						// console.log('没有找到拟采购清单')
						// items.u_u_pur_item = null;
						// items.u_u_pur_item_EXName = null;
					}
					dgrid.refreshView();
				}
			);
		}

		//选择清单名称带出一些数据
		if (items.u_cnt_item) {
		}
		console.log("useUpdateRow end");
	}, "p_form_equipment_list_d");
	function useDataFun(k, t, v) {
		function saveData(k, v) {
			localStorage.setItem(k, JSON.stringify(v));
		}
		function getData(k) {
			const storedValue = localStorage.getItem(k);
			if (storedValue) {
				return JSON.parse(storedValue);
			}
			return null;
		}
		function clearData(k) {
			localStorage.removeItem(k);
		}
		function AsyncTypeData(k, t, v) {
			switch (t) {
				case "save":
					saveData(k, v);
					break;
				case "get":
					return getData(k);
					break;
				case "clear":
					clearData(k);
					break;
				default:
					console.log("Invalid t");
			}
		}
		AsyncTypeData(k, t, v);
	}
	useClick(function ({ args }) {
		console.log(args, "1XXX1???");
		useDataFun("ArrData", "clear");
		useDataFun("ArrData", "save", dgrid.getRows());
	}, "imp_push");
	{
		//表体订阅字段更新逻辑BEGIN
		// 统一的更新逻辑函数
		// const updateCosts = (args) => {
		//   // // 未税单价   = 含税单价/1+税率
		//   // args[0].u_sub_prc = (args[0].u_sub_prc_vat || 0) / (1 + (args[0].u_sub_tax_rate || 0));
		//   // 含税单价   = 未税单价*（1+税率）
		//   args[0].u_sub_prc_vat = (args[0].u_sub_prc || 0) * (1 + (args[0].u_sub_tax_rate || 0));
		//   // 含税成本 = 数量 * 含税单价
		//   args[0].u_sub_cost_vat = (args[0].u_sub_qty || 0) * (args[0].u_sub_prc_vat || 0);
		//   // 成本未税 = 数量 * 含税单价 / 1+税率
		//   args[0].u_sub_cost = (args[0].u_sub_qty || 0) * (args[0].u_sub_prc || 0);
		//   // args[0].u_sub_cost = ((args[0].u_qty || 0) * (args[0].u_sub_prc_vat || 0)) / (1 + (args[0].u_sub_tax_rate || 0));
		//   // 采购
		//   // args[0].u_pur_prc = (args[0].u_pur_prc_vat || 0) / (1 + args[0].u_pur_tax_rate || 0);
		//   args[0].u_pur_prc_vat = (args[0].u_pur_prc || 0) * (1 + args[0].u_pur_tax_rate || 0);
		//   args[0].u_pur_cost_vat = (args[0].u_pur_qty || 0) * (args[0].u_pur_prc_vat || 0);
		//   args[0].u_pur_cost = (args[0].u_pur_qty || 0) * (args[0].u_pur_prc || 0);
		//   // args[0].u_pur_cost = ((args[0].u_qty || 0) * (args[0].u_pur_prc_vat || 0)) / (1 + (args[0].u_pur_tax_rate || 0));
		//   // 自制
		//   // args[0].u_self_prc = (args[0].u_self_prc_vat || 0) * (1 + args[0].u_self_tax_rate || 0);
		//   args[0].u_self_prc_vat = (args[0].u_self_prc || 0) * (1 + args[0].u_self_tax_rate || 0);
		//   args[0].u_self_cost_vat = (args[0].u_self_qty || 0) * (args[0].u_self_prc_vat || 0);
		//   args[0].u_self_cost = (args[0].u_self_qty || 0) * (args[0].u_self_prc || 0);
		//   // args[0].u_self_cost = ((args[0].u_qty || 0) * (args[0].u_self_prc_vat || 0)) / (1 + (args[0].u_self_tax_rate || 0));
		// };
		// 用于绑定触发字段和更新的通用函数
		// const createChangeHandler = (fields) => {
		//   fields.forEach((field) => {
		//     useDataIndexChange(({ args, instance }) => {
		//       // updateCosts(args);
		//       instance.updateRow(args[0]);
		//     }, field);
		//   });
		// };
		// 绑定字段变化以触发更新
		// createChangeHandler([
		//   "p_form_equipment_list_d.u_qty",
		//   "p_form_equipment_list_d.u_sub_qty",
		//   "p_form_equipment_list_d.u_pur_qty",
		//   "p_form_equipment_list_d.u_self_qty",
		//   "p_form_equipment_list_d.u_sub_prc",
		//   "p_form_equipment_list_d.u_sub_prc_vat",
		//   "p_form_equipment_list_d.u_sub_tax_rate",
		//   "p_form_equipment_list_d.u_pur_prc",
		//   "p_form_equipment_list_d.u_pur_prc_vat",
		//   "p_form_equipment_list_d.u_pur_tax_rate",
		//   "p_form_equipment_list_d.u_self_prc",
		//   "p_form_equipment_list_d.u_self_prc_vat",
		//   "p_form_equipment_list_d.u_self_tax_rate",
		// ]);
	} //表体订阅字段更新逻辑END
	try {
		let _num = 0;
		setInterval(() => {
			const t = dgrid.getRows().length;
			if (t !== _num) {
				dgrid.refreshView();
				_num = t;
			}
		}, 1000);
	} catch (err) {}
	{
		//表体字段汇总逻辑BEGIN
		useUpdateRows(({ args }) => {
			const rows = args[0];
			caculatedgrid();
		}, "p_form_equipment_list_d");

		useUpdateRows(({ args }) => {
			const rows = args[0];
			caculatedgrid();
		}, "p_form_equipment_list_impl");

		useUpdateRows(({ args }) => {
			const rows = args[0];
			caculatedgrid();
		}, "p_form_equipment_list_svc");
	} //表体字段汇总逻辑END

	//自动获取设备清单的实施费用和服务费用
	if (page.oType == page.OType.Add || page.oType == page.OType.Edit) {
		console.log(page.oType); //新增 修改 查看 工作流
		var dgrid1 = $NG.getCmpApi("p_form_equipment_list_impl");
		var dgrid2 = $NG.getCmpApi("p_form_equipment_list_svc");
		var dgrid3 = $NG.getCmpApi("p_form_equipment_list_rd");

		useValuesChange(({ args }) => {
			console.log(args[0]);
			danjvchaxun();
		}, "p_form_equipment_list.u_cnt");
	}
	async function danjvchaxun() {
		await dgrid1.clearRows();
		await dgrid2.clearRows();
		await dgrid3.clearRows();
		if (dgrid1) {
			await $NG.execServer(
				"get_impl_cost_budget_info",
				{
					phid_pc: mstform.getItem("phid_pc").getValue(),
				},
				function (res) {
					console.log(`实施费请求`, res);
					if (res.count == 0) return;
					const data = JSON.parse(res.data);
					console.log(res.data);
					//默认增行,批量新增表体数据
					var gridArr = []; //定义表体数组
					var gridCount = res.count; //增加的行数,可根据从数据库从取出的数据总数增行
					for (var i = 0; i < gridCount; i++) {
						var gridObj = {};
						//对表体字段进行赋值,可以取数据库中的值进行赋值
						gridObj.u_bill_no = data[i].extendObjects.bill_no;
						gridObj.u_total_impl_amt = data[i].extendObjects.u_total_impl_amt;
						gridObj.u_total_impl_labor_amt =
							data[i].extendObjects.u_total_impl_labor_amt;
						gridObj.u_total_daily_amt = data[i].extendObjects.u_total_daily_amt;
						gridObj.u_total_sec_dev_amt =
							data[i].extendObjects.u_total_sec_dev_amt;
						gridObj.u_invoice_type = data[i].extendObjects.u_invoice_type;
                        gridObj.u_source_phid=data[i].extendObjects.phid
						gridArr.push(gridObj);
                        if(data[i].extendObjects.app_status != 1){
                            if(!window._lsz_catch_status){
                                window._lsz_catch_status = {}
                                window._lsz_catch_status["impl"] = [data[i].extendObjects.bill_no]
                            }else {
                            window._lsz_catch_status["impl"].push(data[i].extendObjects.bill_no)
                            }
                        }
					}
					//调用新增表体行数据的函数
					dgrid1.addRows(gridArr);
                    
				}
			);
		}
		if (dgrid2) {
			await $NG.execServer(
				"get_svc_cost_budget_info",
				{
					phid_pc: mstform.getItem("phid_pc").getValue(),
				},
				function (res) {
					console.log(`服务请求`, res);
					if (res.count == 0) return;
					const data = JSON.parse(res.data);
					console.log(res.data);
					//默认增行,批量新增表体数据
					var gridArr = []; //定义表体数组
					var gridCount = res.count; //增加的行数,可根据从数据库从取出的数据总数增行
					for (var i = 0; i < gridCount; i++) {
						//对表体字段进行赋值,可以取数据库中的值进行赋值
						var gridObj = {};
						gridObj.u_bill_no = data[i].extendObjects.bill_no;
						gridObj.u_total_svc_amt = data[i].extendObjects.u_total_svc_amt;
						gridObj.u_total_svc_labor_amt =
							data[i].extendObjects.u_total_svc_labor_amt;
						gridObj.u_total_daily_amt = data[i].extendObjects.u_total_daily_amt;
						gridObj.u_source_phid = data[i].extendObjects.phid;
						// gridObj.u_invoice_type = data[i].extendObjects.u_invoice_type;
                        if(data[i].extendObjects.app_status != 1){
                            if(!window._lsz_catch_status){
                                window._lsz_catch_status = {}
                                window._lsz_catch_status["svc"] = [data[i].extendObjects.bill_no]
                            }else{
                            window._lsz_catch_status["svc"].push(data[i].extendObjects.bill_no)
                            }
                        }
						gridArr.push(gridObj);
					}
					//调用新增表体行数据的函数
					dgrid2.addRows(gridArr);
				}
			);
		}
		if (dgrid3) {
			await $NG.execServer(
				"getDevCostBudgetInfo",
				{ phid_pc: mstform.getItem("phid_pc").getValue() },
				function (res) {
					console.log(`研发费请求`, res);
					if (res.count == 0) return;
					const data = JSON.parse(res.data);
					console.log(res.data);
					//默认增行,批量新增表体数据
					var gridArr = []; //定义表体数组
					var gridCount = res.count; //增加的行数,可根据从数据库从取出的数据总数增行
					for (var i = 0; i < gridCount; i++) {
						//对表体字段进行赋值,可以取数据库中的值进行赋值
						var gridObj = {};
						gridObj.u_bill_no = data[i].extendObjects.bill_no;
						gridObj.u_rdrg_expenses_total =
							data[i].extendObjects.u_total_labor_amt;
						gridObj.u_rcfy_total = data[i].extendObjects.u_total_daily_amt;
						gridObj.u_rd_expenses = data[i].extendObjects.u_total_dev_amt;
						gridObj.u_source_phid = data[i].extendObjects.phid;
						// gridObj.u_invoice_type = data[i].extendObjects.u_invoice_type;
						gridArr.push(gridObj);
                        if(data[i].extendObjects.app_status != 1){
                            console.log("未审核");
                            if(!window._lsz_catch_status){
                                console.log(`不存在`);
                                window._lsz_catch_status = {}
                                window._lsz_catch_status["rd"] = [data[i].extendObjects.bill_no]
                            }else {
                                window._lsz_catch_status["rd"].push(data[i].extendObjects.bill_no)
                            }
                        }
					}
					//调用新增表体行数据的函数
					dgrid3.addRows(gridArr);
				}
			);
		}
        console.log(`是否审核----`,window._lsz_catch_status);
        if(window._lsz_catch_status){
            const _map = window._lsz_catch_status
            let title = '预算费用包含未审核明细：'
            for(let key in window._lsz_catch_status){
                switch (key){
                    case 'impl':
                        _map[key].forEach(item=>{
                            title += `实施费用预算编码：${item}、`
                        })
                        break;
                    case 'svc':
                        _map[key].forEach(item=>{
                            title += `服务费用预算编码：${item}、`
                        })
                        break; 
                    case 'rd':
                        _map[key].forEach(item=>{
                            title += `研发费用预算编码：${item}、`
                        })
                        break;
                }
        }
        $NG.alert(title)
	}
}
	$NG.updateUI((updater, state) => {
		updater.fieldSetForm.p_form_equipment_list.u_cnt_no.setProps({
			// 双击事件
			onDoubleClick() {
				var u_cnt_phid = $NG
					.getCmpApi("p_form_equipment_list")
					.getItem("u_cnt_no")
					.getValue();
				if (u_cnt_phid) {
					// 弹出确认框
					// var isConfirmed = $NG.confirm("您确定要跳转到合同信息吗？");
					// if (isConfirmed) {
					$NG.open(
						"http://nginx.clouddev.hisense.com" +
							"/PMS/PCM/CntM/CntMEdit?otype=view&id=" +
							u_cnt_phid,
						{ AppTitle: "合同信息" }
					);
					// }
				}
			},
		});
	});

	//function
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	function caculatedgrid() {
		console.log("caculatedgrid begin");
		let sum_cost_vat = 0;
		let sum_cost = 0;
		let sum_cnt_amt_vat = 0;
		let sum_sub_cost_vat = 0;
		let sum_sub_cost = 0;
		let sum_pur_cost_vat = 0;
		let sum_pur_cost = 0;
		let sum_self_cost_vat = 0;
		let sum_self_cost = 0;
		let sum_impl_cost_vat = 0;
		let sum_svc_cost_vat = 0;
		let u_total_cnt_amt_vat = mstform.getItem("u_total_cnt_amt_vat").getValue(); //合同总额
		let u_win_bid_svc_amt = mstform.getItem("u_win_bid_svc_amt").getValue(); //中标服务费

		const DRows = $NG.getCmpApi("p_form_equipment_list_d").getRows(); //设备清单页签
		const implRows = $NG.getCmpApi("p_form_equipment_list_impl").getRows(); //实施费页签
		const svcRows = $NG.getCmpApi("p_form_equipment_list_svc").getRows(); //服务费页签
		DRows.forEach((items) => {
			sum_cnt_amt_vat += parseFloat(items.u_cnt_amt_vat) || 0; //合同现额
			sum_sub_cost_vat += parseFloat(items.u_sub_cost_vat) || 0; // 拟分包成本含税
			sum_sub_cost += parseFloat(items.u_sub_cost) || 0; // 拟分包成本未税
			sum_pur_cost_vat += parseFloat(items.u_pur_cost_vat) || 0; // 拟采购成本含税
			sum_pur_cost += parseFloat(items.u_pur_cost) || 0; // 拟采购成本未税
			sum_self_cost_vat += parseFloat(items.u_self_cost_vat) || 0; //拟自制成本含税
			sum_self_cost += parseFloat(items.u_self_cost) || 0; //拟自制成本未税
		});
		implRows.forEach((items) => {
			sum_impl_cost_vat += parseFloat(items.u_total_impl_amt);
		});
		svcRows.forEach((items) => {
			sum_svc_cost_vat += parseFloat(items.u_total_svc_amt);
		});

		sum_cost_vat =
			sum_sub_cost_vat +
			sum_pur_cost_vat +
			sum_self_cost_vat +
			sum_impl_cost_vat +
			sum_svc_cost_vat;
		sum_cost =
			sum_sub_cost +
			sum_pur_cost +
			sum_self_cost +
			sum_impl_cost_vat +
			sum_svc_cost_vat;

		$NG.updateState((updater) => {
			updater.data.p_form_equipment_list.setProps({
				u_cnt_amt_vat: sum_cnt_amt_vat, //合同现额
				u_sub_cost: sum_sub_cost_vat, //拟分包含税
				u_sub_cost_amt: sum_sub_cost, //拟分包不含税
				u_pur_cost_vat: sum_pur_cost_vat, //拟采购成本含税
				u_pur_cost_amt: sum_pur_cost, //拟采购成本未税
				u_self_cost_vat: sum_self_cost_vat, //拟自制成本含税
				u_self_cost: sum_self_cost, //拟自制成本未税
				u_implement_amt: sum_impl_cost_vat, //实施费
				u_svc_cost_amt: sum_svc_cost_vat, //服务费

				u_total_cost_amt_vat: sum_cost_vat, //总成本含税
				u_total_cost_amt: sum_cost, //总成本不含税
				u_revenue_cost_gm: u_total_cnt_amt_vat - sum_cost_vat, //收入成本毛利
				u_signed_gm_rate:
					(u_total_cnt_amt_vat - sum_cost_vat) / u_total_cnt_amt_vat, //签单毛利率
				u_svc_amt_rate: u_win_bid_svc_amt / u_total_cnt_amt_vat, //服务费率
				u_bid_gm_rate:
					(u_total_cnt_amt_vat - sum_cost_vat - u_win_bid_svc_amt) /
					u_total_cnt_amt_vat, //投标毛利率

				u_sub_cost_ratio: sum_sub_cost_vat / sum_cost_vat, //拟分包成本占比
				u_pur_cost_ratio: sum_pur_cost_vat / sum_cost_vat, //拟采购成本占比
				u_self_cost_ratio: sum_self_cost_vat / sum_cost_vat, //拟自制成本占比
				u_implement_cost_ratio: sum_impl_cost_vat / sum_cost_vat, //实施费占比
				u_svc_cost_ratio: sum_svc_cost_vat / sum_cost_vat, //服务费占比
			});
		});
		console.log(
			"u_total_cost_amt_vat:" +
				mstform.getItem("u_total_cost_amt_vat").getValue()
		);
		console.log("caculatedgrid end");
	}

	function insertClick() {
		var dgrid = $NG.getCmpApi("p_form_equipment_list_d");
		var orirow =
			dgrid.getCheckedIndexes()[0] !== undefined
				? dgrid.getCheckedIndexes()[0]
				: dgrid.getAllData().table.newRow.length;
		var maxrow = dgrid.getAllData().table.newRow.length;
		console.log(orirow);
		dgrid.addRows();
		setTimeout(function () {
			console.log(maxrow);
			dgrid.moveRow(maxrow, orirow + 1);
		}, 100); // 延迟 100 毫秒，视具体情况可以调整这个值
	}

	function getCntMInfoByPhid(params) {
		$NG.execServer(
			"getCntMInfoByPhid",
			{ phid: mstform.getItem("u_cnt").getValue() },
			function (res) {
				const datas = JSON.parse(res.data)[0].extendObjects;
				console.log(datas);
				//帮助字段赋值
				$NG.updateState((updater) => {
					//【注意这里的表名不能为控件ID，必须要是表名】
					updater.data.p_form_equipment_list.setProps({
						u_total_cnt_amt_vat: datas.cnt_sum_vat_fc,
						u_cnt_amt_vat: datas.cnt_sum_vat_fc,
						u_cnt_no: {
							value: datas.pcm_phid,
							label: datas.pcm_no,
						},
						u_product_line: {
							value: datas.midwife_phid,
							label: datas.midwife_name,
						},
						u_cnt_type: {
							value: datas.pct_id,
							label: datas.pct_name,
						},
						u_customer: {
							value: datas.customer_id,
							label: datas.customer_name,
						},
						u_invoice_type: {
							value: datas.invoice_type_phid,
							label: datas.invoice_type_name,
						},
                        u_cnt_amt:datas.cnt_sum_vat_fc
					});
				});
			}
		);
	}
	function getCntDInfoByPhid(record) {
		$NG.execServer(
			"getCntDInfoByPhid",
			{
				cnd_id: mstform.getItem("u_cnt").getValue(),
				phid: record.u_cnt_item,
			},
			function (res) {
				if (res.count > 0) {
					var data = JSON.parse(res.data)[0].extendObjects; //单返回值
					record.u_cnt_item_no = data.item_no; //合同清单编码
					record.u_spec = data.user_ggxh; //规格型号
					record.u_msunit = data.unit_phid;
					record.u_msunit_EXName = data.unit_name; //计量单位
					record.u_tech_params = data.user_jscs; //技术参数
					record.u_brand = data.brand_phid;
					record.u_brand_EXName = data.brand_name; //品牌
					record.u_pc_subitem_category = data.user_gcfxfl; //工程分项分类
					record.u_qty = data.qty; //数量
					record.u_cnt_item_tax_rate = data.taxrate; //税率

					record.u_cnt_prc_vat = data.prc_vat_fc; //含税单价
					record.u_cnt_prc = data.prc_fc; //未税单价
					record.u_cnt_amt_vat = data.amt_vat_fc; //含税金额
					record.u_cnt_amt = data.amt_fc; //未税金额
				} else {
					console.log(record.u_cnt_item + "没有找到合同清单");
				}
				dgrid.refreshView();
			}
		);
	}
	function getCntDInfoByNo(record) {
		if (mstform.getItem("u_cnt_no").getValue() && record.u_cnt_item_no) {
			$NG.execServer(
				"getCntDInfoByNo",
				{
					cnd_id: mstform.getItem("u_cnt_no").getValue(),
					item_no: "'" + record.u_cnt_item_no + "'",
				},
				function (res) {
					if (res.count > 0) {
						var data = JSON.parse(res.data)[0].extendObjects; //单返回值

						record.u_cnt_item = data.phid; //合同清单ID
						record.u_cnt_item_EXName = data.item_name; //合同清单名称
						record.u_model = data.user_ggxh; //规格型号
						u_msunit = data.unit_phid; //计量单位
						u_msunit_EXName = data.unit_name; //计量单位
					} else {
						console.log("没有找到合同清单");
						record.u_cnt_item = null;
						record.u_cnt_item_EXName = null;
					}
					dgrid.refreshView();
				}
			);
		}
	}

	function getPtInfoByPhid() {
		if (mstform.getItem("phid_pc").getValue()) {
			getSbqdCountByPhidPc();
			$NG.execServer(
				"getPtInfoByPhid",
				{ phid: mstform.getItem("phid_pc").getValue() },
				function (res) {
					const datas = JSON.parse(res.data)[0].extendObjects;
					console.log(datas);
					$NG.updateState((updater) => {
						//【注意这里的表名不能为控件ID，必须要是表名】
						updater.data.p_form_equipment_list.setProps({
							u_pc_no: datas.pc_no,
							//售前顾问
							u_sqgw: {
								value: datas.user_sqgw_phid,
								label: datas.user_sqgw_name,
							},
							//项目经理
							u_project_manager: {
								value: datas.project_manager_phid,
								label: datas.project_manager_name,
							},
							//事业部
							u_division: {
								value: datas.phid_org_phid,
								label: datas.phid_org_name,
							},
							//区域中心
							u_regional_center: {
								value: datas.regional_center_phid,
								label: datas.regional_center_name,
							},
						});
					});
				}
			);
		}
	}

	function cntMFilter() {
		$NG.updateUI((updater, state) => {
			updater.fieldSetForm.p_form_equipment_list.u_cnt.setProps({
				onBeforeOpen: async () => {
					var phid_pc = $NG
						.getCmpApi("p_form_equipment_list")
						.getItem("phid_pc")
						.getValue();
					if (!phid_pc) {
						$NG.alert("请先选择项目");
						return false;
					} else {
						return true;
					}
				},
				...(!!$NG
					.getCmpApi("p_form_equipment_list")
					.getItem("phid_pc")
					.getValue() && {
					clientSqlFilter: {
						bill_type: 1,
						phid_pc: $NG
							.getCmpApi("p_form_equipment_list")
							.getItem("phid_pc")
							.getValue(),
					},
				}),
			});
		});
	}

	function cntDFilter() {
		$NG.updateUI((updater) =>
			updater.editGrid.p_form_equipment_list_d.u_cnt_item.setProps((p) => {
				return {
					...p,
					editor: {
						...p.editor,
						clientSqlFilter: {
							pphid:
								$NG
									.getCmpApi("p_form_equipment_list")
									.getItem("u_cnt_no")
									.getValue() || 0,
						},
					},
				};
			})
		);
	}

	//设备清单数量
	function getSbqdCountByPhidPc() {
		$NG.execServer(
			"getSbqdCountByPhidPc",
			{ phid_pc: mstform.getItem("phid_pc").getValue() },
			(res) => {
				if (res.count == 0) return;
				const _data = JSON.parse(res.data)[0].extendObjects;
				console.log(`清单数量`, _data);
				if (_data.count > 0) {
					lock = false;
				} else {
					lock = true;
				}
			}
		);
	}
});
// 自动生产编码 ** 如果想复用，请在全局文件中定义一个 变量：let maxNo=null
ts();
function ts() {
	$NG.execServer(
		"autoSbqdno",
		{ num: formatDate(new Date(), "YYYYmmDD") },
		function (res) {
			if (res.count !== 0) {
				const _data = JSON.parse(res.data)[0].extendObjects;
				console.log(`最大编号`, _data);
				maxNo = Number(_data.u_equipment_list_no);
			} else {
				maxNo = Number(formatDate(new Date(), "YYYYmmDD") + "000000");
			}
		}
	);
}
function autoCreateNo(int) {
	let str = String(maxNo).slice(-6);
	let num = Number(str) + int;
	const s = formatDate(new Date(), "YYYYmmDD") + String(num).padStart(6, "0");
	console.log(`测试编号`, s, str, num);
	return s;
}
// 日期格式化
function formatDate(dateStr, outputFormat) {
	const date = new Date(dateStr);

	if (isNaN(date)) {
		return "无效的日期字符串";
	}

	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, "0");
	const day = String(date.getDate()).padStart(2, "0");
	const hours = String(date.getHours()).padStart(2, "0");
	const minutes = String(date.getMinutes()).padStart(2, "0");

	let formattedDate;

	switch (outputFormat) {
		case "yyyy-mm-dd":
			formattedDate = `${year}-${month}-${day}`;
			break;
		case "yyyy-mm-dd HH:mm":
			formattedDate = `${year}-${month}-${day} ${hours}:${minutes}`;
			break;
		// 可以根据需要继续添加其他格式的处理逻辑
		case "YYYYmmDD":
			formattedDate = `${year}${month.padStart(2, "0")}${day.padStart(2, "0")}`;
			break;
		default:
			formattedDate = "不支持的输出格式";
	}

	return formattedDate;
}

//获取合同数量
function getCntCount(table, key, fun, otherFun) {
	if (!$NG.getCmpApi(table).getItem("phid_pc").getValue()) return;
	$NG.execServer(
		"getCntCount",
		{ type: 1, phid_pc: $NG.getCmpApi(table).getItem("phid_pc").getValue() },
		(res) => {
			console.log(res, "count");
			switch (res.count) {
				case 0:
					return;
				case 1:
					const datas = JSON.parse(res.data)[0].extendObjects;
					const temp_map = {};
					temp_map[key] = datas.phid;
					temp_map[`${key}_EXName`] = datas.bill_name;
					$NG.updateState((updater) => {
						updater.data[table].setProps({
							...temp_map,
						});
						setTimeout(() => {
							fun();
							if (otherFun) {
								otherFun();
							}
						}, 200);
					});
			}
		}
	);
}
// let timeId = 0;
// let __lock = true;
// try {
//   timeId = setInterval(() => {
//     console.log(`查询节点一次~~~`);
//     const node = document.querySelectorAll(".nowrap");
//     if (node || node.length !== 0) {
//       if (__lock) {
//         node.forEach((item) => {
//           if (item instanceof HTMLDivElement && !item.querySelector("*")) {
//             const str = item.textContent;
//             console.log(str);
//             switch (str) {
//               case "拟采购":
//               case "拟分包":
//               case "拟自制":
//                 //                                颜色位置red可以改成rgb、rgba  或  16进制码：#FFFFFFFF
//                 item.style.setProperty("background", "red", "important");
//             }
//           }
//         });
//       }
//       //查询后清除定时器
//       __lock = false;
//       clearInterval(timeId);
//     }
//   }, 500);
// } catch (err) {
//   // 发生异常清除定时器
//   clearInterval(timeId);
// }
